import { FC, useEffect } from "react";
import { QuestionInfoPropsType } from "./interface";
import { Form, Input } from "antd";
import TextArea from "antd/es/input/TextArea";

const PropComponent: FC<QuestionInfoPropsType> = (
  props: QuestionInfoPropsType
) => {
  const { text = "", desc = "", disabled = false, onChange = () => {} } = props;
  const [form] = Form.useForm();

  useEffect(() => {
    form.setFieldsValue({ text, desc });
  }, [text, desc, form]);

  function handleValuesChange() {
    // console.log(form.getFieldsValue());
    onChange?.(form.getFieldsValue());
  }
  return (
    <Form
      layout="vertical"
      initialValues={{ text, desc }}
      disabled={disabled}
      form={form}
      onValuesChange={handleValuesChange}
    >
      <Form.Item
        label="标题内容"
        name="text"
        rules={[{ required: true, message: "请输入标题内容" }]}
      >
        <Input></Input>
      </Form.Item>
      <Form.Item
        label="描述内容"
        name="desc"
        rules={[{ required: true, message: "请输入描述内容" }]}
      >
        <TextArea rows={4} />
      </Form.Item>
    </Form>
  );
};

export default PropComponent;
